<template>
    <div class="details">
        <div class="box80">
            <div class="wid100">
                <div class="details_l">
                    <div class="details_l_t">
                        <div class="cont">
                            <el-popover placement="right" trigger="click" class="list_S" v-model="detailsShow" popper-class="details-class">
                                <el-button size="mini" type="text" @click="detailsShow = false" icon="el-icon-error"></el-button>
                                <div class="tp">选择设置项包含的信息</div>
                                <div class="contcheck">
                                    <div class="ser">
                                        <div v-for="(item,index)  in columnShowHideList" :key="index" class="li_list" >
                                            <input :checked="item.isDefault ? 'checked' : ''" :name="'checkbox'+index" @click="changeColumnSH(index,item)" type="checkbox"/>
                                            <span >{{item.attrName}}</span>
                                        </div>
                                    </div>    
                                        <div class="btn">
                                            <el-button type="primary"  @click="detailsShow = false">确定</el-button>
                                        </div>
                                </div>
                                <el-button slot="reference"><img src="@/assets/images/icon9_271.png" alt="">设置对比参数</el-button>
                            </el-popover>
                            <button  @click="hideXiangTong" ><img src="@/assets/images/icon12_06.png" alt="">隐藏相同参数</button>
                        </div>
                        <div class="xian"></div> 
                        <div class="cont">
                            <button  @click="checkAll" ><img src="@/assets/images/yansy.png" alt="">查看全部</button>
                        </div>
                    </div>
                    <div class="details_l_b">
                        <ul>
                            <li v-for="(item,index)  in columnShowHideList" v-if="columnShowHideList[index].isDefault">{{item.attrName}}</li>
                        </ul>
                    </div>
                </div>
                <!--查看图片 -->
                <el-dialog :visible.sync="showPic" v-dialogDrag custom-class="imgsAMG dee">
                    <span><img :src="showPicUrl" /></span>
                </el-dialog>
                <div class="details_r">
                    <div class="details_r_list" v-for="item in tableData" :key="item.id">
                        <div class="details_r_t">
                            <div class="conts">
                                <img @click="viewPicture(ImgPath+item.waiGuanPic)" :src="ImgPath+item.waiGuanPic" class="imhs" alt="">
                            </div>
                        </div>
                        <div class="details_r_b">
                            <ul>
                                <li v-for="(showItem,index)  in columnShowHideList" v-if="columnShowHideList[index].isDefault">
                                    <span style="cursor: pointer;color: #5962a3;
    font-weight: bold;" v-if="showItem.attrName =='品牌'" @click="brandPage(item.brandId)">{{item[showItem.attrIndex]}}</span>
                            <span v-else class="ds">
                                <img @click="viewPicture(ImgPath+item[showItem.attrIndex])" :src="ImgPath + item[showItem.attrIndex]" v-if="showItem.valType == 'image' && item[showItem.attrIndex] != null  && item[showItem.attrIndex] != ''" width="100" height="100" />
                                <a :href="ImgPath + item[showItem.attrIndex]"  v-else-if="showItem.valType == 'file' && item[showItem.attrIndex] != null && item[showItem.attrIndex] != ''"> <i  class="avatar-uploader-icon el-icon-notebook-2"></i></a>
                                <span v-else-if="showItem.attrName == '效果描述' || showItem.attrName == '产品标签'" class="ioni">
                                     <el-popover placement="top" trigger="hover" width="400">
                                       {{(item[showItem.attrIndex])}}
                                        <div slot="reference"><span id="wenzi2">{{getSubStr(item[showItem.attrIndex])}}</span></div>
                                    </el-popover>
                                </span>
                                <span v-else>{{item[showItem.attrIndex]}}</span>
                            </span>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
    </div>
</template>
<script>
export default {
    data(){
        return{
            showPic:false, //查看图片
            showPicUrl:'', //图片地址
            detailsShow:false,
            tableData:[],
            columnShowHideList:[],
        }
    },
    created(){
        this.initData()
        this.loadShowHideList()
    },
    methods:{
        
    
            getSubStr(val){
                var str = val
                if(val != null && val != '' && val.length > 30){
                    str = val.substring(0,30)+"..."
                }
                return str
            },
        brandPage(id){
            let routeUrl = this.$router.resolve({
                path: "/brandPage?id="+id
            });
            window.open(routeUrl.href, '_blank');
        },
        viewPicture(url){
            this.showPic = true
            this.showPicUrl = url
        },
        checkAll(){
            for(var i = 0;i<this.columnShowHideList.length;i++){
                console.log(i)
                this.columnShowHideList[i].isDefault = true
            }
        },
        loadShowHideList(){
            let self = this
            this.$http.get('/api/banner/stlamps/attributes',{},function(res){
                if(res.success){
                    self.columnShowHideList = res.data
                    // for(var i = 0;i<self.columnShowHideList.length;i++){
                    //     self.columnShowHideList[i].isDefault = true
                    // }
                }
            })
        },
        initData(){
            var ids = this.$route.query.ids
            if(ids.length > 0){
                ids = ids.substring(0,ids.length -1)
            }
            let self =this
            this.$http.postObj('/api/banner/stlamps/json',{ids:ids},function(res){
                self.tableData = res.data
                if(self.tableData.length <6){
                    // for(var i =self.tableData.length;i<6;i++){
                    //     self.tableData.push({
                    //         isFalse:true
                    //     })
                    // }
                }
            })
        },
        hideXiangTong(){
            for(var i = 0;i<this.columnShowHideList.length;i++){
                this.columnShowHideList[i].isDefault = false
            }
            
            for(var i = 0;i<this.tableData.length;i++){
                if(i == 0 ){ //|| this.tableData[i].isFalse
                    continue;
                }
                for(var j =0;j<this.columnShowHideList.length;j++){
                    console.log(this.columnShowHideList[j].isDefault,this.tableData[i][this.columnShowHideList[j].attrIndex])
                }
                for(var j =0;j<this.columnShowHideList.length;j++){
                    if(this.columnShowHideList[j].isDefault == false && this.tableData[i][this.columnShowHideList[j].attrIndex] != this.tableData[0][this.columnShowHideList[j].attrIndex]){
                        this.columnShowHideList[j].isDefault = true
                    }
                }
            //     if(this.columnShowHideList[0].value == false && this.tableData[i].contestTypeStr != this.tableData[0].contestTypeStr){
            //         this.columnShowHideList[0].value = true
            //     }
            }
        },
        changeColumnSH(index,item){item.isDefault = !item.isDefault;
        }
    }
}
</script>
<style rel="stylesheet/scss" lang="scss">
#wenzi2{
    overflow:hidden; 
    display:-webkit-box; 
    -webkit-box-orient:vertical; 
    -webkit-line-clamp:2;
    text-overflow:ellipsis;
  word-break: break-all;
  height: 45px;
}
.details .box80 .details_l .details_l_t button.fanhuo{
    margin-bottom: 10px;
}
.details .box80 .details_l .details_l_t button.fanhuo span{
        width: 18px;
    height: 18px;
    text-align: center;
    line-height: 19px;
    border-radius: 50%;
    border: 1px solid #fff;
    display: inline-block;
    position: relative;
    cursor: pointer;
    top:2px;
    margin-right: 9px;
}
.details-class {
    padding: 0;
    .contcheck {
        width: 770px;
        padding: 5%;
        .ser{
            overflow: hidden;
            margin: 12px
        }
        .li_list {
            width: 25%;
            float: left;
            margin-right: 0;
                input {
                position: relative;
                top: 2px;
                margin-right: 3px;
            }
        }
    }
    .tp {
        background-color: #5a63a3;
        color: #fff;
        padding: 15px 25px;
    }
    .el-icon-error {
        color: #fff;
        font-size: 20px;
    }
    .btn {
        .el-button--primary{
             padding: 7px 25px;
                background-color: #5a63a3;
                border-radius: 4px;
                border: none;
        }
    }
}
.details{
    background: #f4f4fd;
    box-shadow: none;
    .box80{
        .wid100{
            box-shadow: 7px 6px 10px 0px rgba(90, 99, 163, 0.06);
        }
        padding: 120px 0 50px;
        .details_l{
            width: 14.2857%;
            float: left;
            .details_l_t{
                background-color: #5962a3;
                box-shadow: 1px 1px 10px 0px #f6f6f6;
                border-radius: 4px;
                height: 326px;
                .cont{
                    padding: 20px 20px 10px;
                    .el-checkbox__label{
                        color:#fff;
                    }
                    .list_S{
                        .el-button{padding: 0;}
                    }
                    .tab{
                        span{
                            font-size: 16px;
                            color: #fff;
                        }
                        img{
                            display: inline-block;
                            margin-left: 10px;
                            position: relative;
                            top: 4px;
                        }
                    }
                }
                .xian{
                    background-color: rgba(238, 238, 238, 0.3);
                    height: 2px;
                }
                button{
                    color: #fff;
                    border: none;
                    background: none;
                    font-size: 16px;
                    margin-bottom: 15px;
                    img{
                        margin-right: 6px;
                        margin-left: 0;
                        position: relative;
                        top: 3px;
                        display: inline-block;
                    }
                }
                .el-radio{
                    color: #fff;  
                    margin-bottom: 15px;
                    &:last-child{
                        margin-bottom: 0;
                    }             
                    .el-radio__inner{
                        border: 1px solid #fff;
                        background: none;
                    }  
                    .el-radio__input.is-checked .el-radio__inner{
                        border-color:#fff;
                        background: none;
                        &:after{
                           width: 6px;
                           height: 6px;
                        }
                    }
                    .el-radio__label{
                        font-size: 16px;
                        color: #fff !important;
                    }
                }
                .el-radio__input.is-checked+.el-radio__label{
                    color: #fff;
                }
            }
            .details_l_b{
                margin-top: 20px;
                background-color: #5962a3;
                box-shadow: 1px 1px 10px 0px #f6f6f6;
                border-radius: 4px;
                ul li{
                    text-align: center;
                    color: #fff;
                     padding: 18px 5px;
                     height: 60px;
                    &:nth-child(even){
                        background-color: rgba(246, 247, 251, 0.1);
                    }
                }
            }
        }
        .details_r{
            width: 85.7143%;
            float: left;
            .details_r_list{
                width: 16.666%;
                float: left;
                text-align: center;
                position: relative;
                // &:hover::before{
                //     content: '';
                //     width: 100%;
                //     height: 100%;
                //     position: absolute;
                //     top: 0;
                //     left: 0;
                //     background-color: rgba(89, 98, 163, 0.4)
                // }
                .details_r_t{
                    background: #fff;
                    padding: 20px;
                    height: 326px;
                    border-left: 1px solid #eeeeee;
                    .conts{
                        position: relative;
                        height: 100%;
                        .imhs{
                            max-width: 100%;
                            max-height: 100%;
                        }
                        .control{
                            position: absolute;
                            background-color: #eeeeee;
                            box-shadow: 2px 2px 14px 0px rgba(0, 0, 0, 0.6);
                            border-radius: 4px;
                            top: 10px;
                            left: 50%;
                            transform:translateX(-50%);
                            padding: 8px 10px 2px;
                            cursor: pointer;
                            width: 100px;
                            img{
                                margin-left: 6px;
                                box-shadow: 0px 0px 5px 0px #dadada;
                                    border-radius: 50%;
                                    display: inline-block;
                                &:first-child{
                                    margin-left: 0;
                                }
                            }
                        }
                    }
                }
                .details_r_b{
                    margin-top: 20px;
                    li{
                        padding: 18px 5px;
                        height: 60px;
                        background: #fff;
                        border-left: 1px solid #eeeeee;
                        position: relative;
                        .ds .el-popover__reference{
                            position: absolute;
                            width: 100%;
                            left: 0;
                            top: 6px;
                        }
                        &:nth-child(even) {
                            background-color: rgba(246, 247, 251, 0.1);
                        }
                        img{
                            width: auto;
                            transform: scale(1.4);
                        }
                    }
                }
            }
        }
    }
}
@media (max-width:1500px){
    .details{
        .box80 .details_l .details_l_t{
            button{
                font-size: 14px;
            }
            .el-radio .el-radio__label{
                font-size: 14px;
            }
        } 
    }
    .details .box80 .details_l .details_l_t .cont .tab span{font-size: 12px;}
}
@media (max-width:1330px){
    .details .box80 .details_l .details_l_t{
         .cont{
             padding: 20px 12px;
        }
    }
}
</style>


